﻿@model PagedList<HouseAgencySite.Models.HouseInfos>

@{  
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@*<div>
    <ul class="list-inline" id="orders">
        <li><strong>排序</strong></li>
        <li class="order btn btn-info btn-xs active" o="1">时间</li>
        <li class="order" o="2">价格</li>
        <li class="order" o="3">面积</li>

    </ul>
</div>*@
<div class="product-bg">
    <div class="arrange" id="orders">
        <ul>
            <li><span>排序：</span></li>
            <li class="order list-select" o="1">时间 </li>
            <li class="order" o="2"><a href="#">价格</a></li>
            <li class="order" o="3"><a href="#">面积</a></li>
        </ul>
    </div>
    <div id="searchResult">
        @Html.Partial("SearchResult", Model)
    </div>
</div>

<div id="loading" style="display: none;">数据加载中，请稍后.....</div>
<script src="~/Scripts/MvcPager.js"></script>
<script>
    $(function () {
        //有关地区处理
        $("li", "#cityTab").click(function () {
            $("li", "#cityTab").removeClass("selected");
            $(this).addClass("selected");
            $("li", "#cityTabContent").removeClass("selected");
            $("li", "#areaTabContent").removeClass("selected");
        });
        $("li", "#cityTabContent").click(function () {
            $("li", "#cityTabContent").removeClass("selected");
            $(this).addClass("selected");
            $("li", "#areaTabContent").removeClass("selected");
        });
        $("li", "#areaTabContent").click(function () {
            $("li", "#areaTabContent").removeClass("selected");
            $(this).addClass("selected");
        });
        var appendData = function (el, isAdd, el2) {
            if ($(el2).find("a").html().trim() != "全部") {
                if (isAdd) {
                    $("#" + el).data("f", $("#" + el).data("f") + $(el2).find("a").html().trim() + "/");
                } else {
                    $("#" + el).data("f", $(el2).find("a").html().trim() + "/");
                }
            }
        }
        //重置
        $("#btnResetSearch").click(function () {
            location.reload();
        })
        //单价
        $("li:not(:last,:first)", "#price").click(function () {
            $("li", "#price").removeClass("btn btn-info btn-xs list-select");
            $(this).addClass("btn btn-info btn-xs list-select");
            $("#btnSearchList").click();
        });
        //面积
        $("li:not(:last,:first)", "#mianji").click(function () {
            $("li", "#mianji").removeClass("btn btn-info btn-xs list-select");
            $(this).addClass("btn btn-info btn-xs list-select");
            $("#btnSearchList").click();
        });
        //户型
        $("li:not(:first)", "#huxing").click(function () {
            $("li", "#huxing").removeClass("btn btn-info btn-xs list-select");
            $(this).addClass("btn btn-info btn-xs list-select");
            $("#btnSearchList").click();
        });
        //排序
        $("li:not(:first)", "#orders").click(function () {
            var currentOrder = $("li.active", "#orders");
            $("li", "#orders").removeClass("btn btn-info btn-xs list-select");
            if (currentOrder.html() == $(this).html()) {
                $(this).attr("o", -parseInt($(this).attr("o")));
            }
            $(this).addClass("btn btn-info btn-xs list-select");
            $("#btnSearchList").click();
        })
        $("#btnSearchList").click(function () {
            BindData();
        });
        var BindData = function () {
            var fullPath = "";
            var addr = "";
            var selArea = "";
            var selCity = $.trim($(".selected", "#cityTab").find("a").text());
            if (selCity != "全部" && selCity != null) {
                fullPath += selCity;
                selArea = $.trim($(".selected", "#cityTabContent").find("a").text());
                if (selArea != "全部" && selArea != null) {
                    fullPath += selArea;
                    addr = $.trim($(".selected", "#areaTabContent").find("a").text());
                    if (addr != "全部" && addr != null) {
                        fullPath += addr;
                    }
                }
                fullPath = $.trim(selCity + "/" + selArea + "/" + addr);
            }

            fullPath = fullPath.replace("//", "/");
            var huxing = $.trim($("#huxing").find(".list-select").attr("t"));
            var price = $.trim($("#price").find(".list-select").text());
            var mianji = $.trim($("#mianji").find(".list-select").text());
            var priceLeft = $.trim($("#PriceLeft").val());
            var priceRight = $.trim($("#PriceRight").val());
            var mianjiLeft = $.trim($("#MianJiLeft").val());
            var mianjiRight = $.trim($("#MianJiRight").val());
            var order = $.trim($("#orders").find(".list-select").attr("o"));
            var form = {};
            form.PriceLeft = 0;
            form.PriceRight = 0;
            form.MianJiLeft = 0;
            form.MianJiRight = 0;
            form.MianJi = 0;
            price = price == "不限" ? 0 : price.replace("元", "");
            mianji = mianji == "不限" ? 0 : mianji.replace("㎡", "");
            form.FullPath = fullPath;
            form.HuXing = huxing;
            if (price.length > 0) {
                form.PriceLeft = parseFloat(price);
                form.PriceRight = parseFloat(price);
            }
            if (mianji.length > 0) {
                form.MianJiLeft = parseFloat(mianji);
                form.MianJiRight = parseFloat(mianji);
            }

            if (priceLeft.length > 0) {
                if (isNaN(priceLeft)) {
                    alert("价格请用数字表示！"); return;
                }
                else {
                    form.PriceLeft = parseFloat(priceLeft);
                }
            }
            if (priceRight.length > 0) {
                if (isNaN(priceRight)) {
                    alert("价格请用数字表示！"); return;
                }
                else {
                    form.PriceRight = parseFloat(priceRight);
                }
            }
            if (mianjiLeft.length > 0) {
                if (isNaN(mianjiLeft)) {
                    alert("面积请用数字表示！"); return;
                }
                else {
                    form.MianJiLeft = parseFloat(mianjiLeft);
                }
            }
            if (mianjiRight.length > 0) {
                if (isNaN(mianjiRight)) {
                    alert("面积请用数字表示！"); return;
                }
                else {
                    form.MianJiRight = parseFloat(mianjiRight);
                }
            }
            form.HouseType = location.href.substr(location.href.lastIndexOf("/") + 1, 1);
            var currentPage = $.trim($(".active", ".pagination").find("a").html());
            if (typeof (currentPage) == "undefined" || currentPage.length == 0) {
                currentPage = 1;
            }
            $.ajax({
                asyn: true,
                type: "post",
                url: '@Url.Action("SearchResult")',
                data: { pageIndex: currentPage, orders: order, model: JSON.stringify(form) },
                success: function (d) {
                    $("#searchResult").html(d);
                },
                error: function (ex) {
                    alert("数据加载失败！" + JSON.stringify(ex));
                }
            });
        }
    })
</script>
